package com.cl.erp_2301.controller;

import com.cl.erp_2301.dto.DataDTO;
import com.cl.erp_2301.dto.EmpDTO;
import com.cl.erp_2301.entity.Department;
import com.cl.erp_2301.entity.Emp;
import com.cl.erp_2301.entity.Goods;
import com.cl.erp_2301.mapper.EmpMapper;
import com.cl.erp_2301.Service.DepartmentService;
import com.cl.erp_2301.Service.EmpService;
import com.cl.erp_2301.util.Result;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v2")
public class EmpController {
    @Resource
    private EmpService empService;
    @GetMapping("/emp/listByPage")
    public Result listByPage(int page,int rows){
        Page<Object> page1= PageHelper.startPage(page, rows);
        List<EmpDTO> empDTOList=empService.listByPage();
        DataDTO data=new DataDTO<>();
        data.setRows(empDTOList);
        data.setTotal(data.getTotal());
        return Result.ok(data);

    }

    @ResponseBody
    @RequestMapping("/emp/deplist")
    public Result DepartmentList(){
        List<Department> departmentList=empService.department();
        return Result.okRows(departmentList);
    }
    @ResponseBody
    @RequestMapping("/emp/add")
    public Result add(@RequestParam("username")String username, @RequestParam("name")String name,
                      @RequestParam("gender")Integer gender, @RequestParam("email")String email,
                      @RequestParam("tele")String tele, @RequestParam("address")String address,@DateTimeFormat(pattern = "yyyy-MM-dd")@RequestParam("birthday")Date birthday,@RequestParam("dep")String dep){

        EmpDTO empDTO=new EmpDTO();
        empDTO.setUsername(username);
        empDTO.setName(name);
        empDTO.setGender(gender);
        empDTO.setEmail(email);
        empDTO.setTele(tele);
        empDTO.setAddress(address);
        empDTO.setBirthday(birthday);
        empDTO.setDep(dep);
        empService.add(empDTO);
        return Result.ok();
    }

}
